<?php
namespace app\index\model;

use think\Controller;
use think\Validate;

#公共验证器#

class ComValidate extends Controller {

	#药品添加验证#
	public function drugtypeadd($data){

		$rule = [
		    'typename'  => 'require|max:25'
		];

		$msg = [
		    'typename.require' => '分类名称必须填写',
		    'typename.max'     => '分类名称最多不能超过25个字符'
		];

		$validate = new Validate($rule, $msg);
	
		if(!$validate->check($data)){
			$this->error($validate->getError());
		}

	}

	#药品添加验证#
	public function drugadd($data){

		$rule = [
		    'drugname'  => 'require|max:25',
		    'unit'  => 'require',
		    'spec'  => 'require',
		    'stock'  => 'require',
		    'typeid'  => 'require'
		];

		$msg = [
		    'drugname.require' => '药品名称必须填写',
		    'drugname.max'     => '药品名称最多不能超过25个字符',
		    'unit.require' => '单位必须填写',
		    'spec.require' => '规格必须选择',
		    'stock.require' => '药品库存必须填写',
		    'typeid.require' => '药品分类必须选择'
		];

		$validate = new Validate($rule, $msg);
	
		if(!$validate->check($data)){
			$this->error($validate->getError());
		}
		
	}
	#必填#
	public function requiredata($data,$type='text'){
		if(empty($data)){
			switch ($type) {
				case 'text':
					exit("条件错误~");
					break;
				case 'json':
					json(['msg'=>"条件错误~"]);
				break;
				
			}
		}
	}

}